package com.finger.crowd.controller;

import com.finger.crowd.entity.vo.AddressVO;
import com.finger.crowd.entity.vo.OrderProjectVO;
import com.finger.crowd.entity.vo.OrderVO;
import com.finger.crowd.service.api.OrderService;
import com.finger.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/get/order/project/vo/remote")
    public ResultEntity<OrderProjectVO> getOrderProjectVORemote(@RequestParam("returnId") Integer returnId,
                                                                @RequestParam("projectId") Integer projectId) {
        try {
            OrderProjectVO orderProjectVO = orderService.getOrderProjectVOByReturnId(returnId);

            return ResultEntity.successWithData(orderProjectVO);

        } catch (Exception exception) {
            exception.printStackTrace();

            return ResultEntity.failed(exception.getMessage());
        }

    }

    @RequestMapping("/save/address/remote")
    public ResultEntity<String> saveAddress(@RequestBody AddressVO addressVO) {

        try {
            orderService.saveAddress(addressVO);

            return ResultEntity.successWithOutData();

        } catch (Exception exception) {
            exception.printStackTrace();

            return ResultEntity.failed(exception.getMessage());
        }
    }

    @RequestMapping("/get/address/by/memberId/remote")
    public ResultEntity<List<AddressVO>> getAllAddress(@RequestParam("memberId") Integer memberId) {
        try {

            List<AddressVO> addressVOList = orderService.getAddressByMemberId(memberId);

            return ResultEntity.successWithData(addressVOList);
        } catch (Exception exception) {
            exception.printStackTrace();

            return ResultEntity.failed(exception.getMessage());
        }
    }

    @RequestMapping("/save/order/vo")
    public ResultEntity<String> saveOrderVO(@RequestBody OrderVO orderVO) {

        try {
            orderService.saveOrderVO(orderVO);

            return ResultEntity.successWithOutData();
        } catch (Exception exception) {
            exception.printStackTrace();

            return ResultEntity.failed(exception.getMessage());
        }
    }

}
